<script setup>
import {
  onLaunch,
  onShow,
  onHide,
  onError,
  onPageNotFound,
} from "@dcloudio/uni-app";
import { useDeviceStore } from "@/store";
import { ServiceAPI } from "./api";

// 获取有多少个未读
const getUnreadCount = (callBack) => {
  ServiceAPI.getUnreadMessageCount().then((res) => {
    res.data[1] && callBack(res.data[1] || 0);
  });
};

onLaunch(() => {
  const deviceStore = useDeviceStore();
  deviceStore.setShop(uni.getStorageSync("MyShop"));
  deviceStore.setLang(uni.getStorageSync("lang"));
  // #ifdef MP-WEIXIN
  // checkForUpdate();
  // #endif
  getUnreadCount((l) => {
    uni.setTabBarBadge({
      index: 2,
      text: l + "",
    });
  });
});

onShow(() => {});

onHide(() => {});

onError((error) => {
  console.error("App Error", error);
});

onPageNotFound((res) => {
  console.error("PageNotFound", res);
  uni.redirectTo({
    url: "/pages/404/404",
  });
});
</script>

<style lang="scss">
@import "@/static/css/index.scss";
@import "linge-ui-app/index.scss";
@supports (top: constant(safe-area-inset-top)) {
  page {
    --status-bar-height: constant(safe-area-inset-top);
  }
}

/* 每个页面公共css */
page {
  height: 100%;
  background: $primary-bg;
}

.app-container {
  width: 100vw;
  height: 100vh;
  background: $primary-white;
}

.ml-42 {
  margin-left: 42rpx;
}

.c_box {
  height: 100%;
}

.bar-h {
  padding-top: var(--status-bar-height);
}

.Arab .rtl {
  direction: rtl;
}

.Arab .flip {
  transform: rotate(180deg);
}

.bg_fff {
  background: #fff;
}

/* 调整弹出层z-index */
.uv-popup {
  z-index: 9999 !important;
}

/* 或者调整tabbar的z-index */
.uni-tabbar {
  z-index: 999 !important;
}

/* uv-ui基础样式 */
@import "@climblee/uv-ui/index.scss";
</style>
